package com.limingfeiyu.common.web;

import com.limingfeiyu.common.code.StatusCode;
import lombok.Data;

/**
 * @Author: 黎铭飞羽
 * @Data: 2024-03-01 :   8:31
 * @Description:
 */
@Data
public class ResultBody<T> {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 提示信息，如果有错误时，前端可以获取该字段进行提示
     */
    private String message;
    /**
     * 查询的数据结果数据
     */
    private T data;


    public static ResultBody ok() {
        return new ResultBody().code(StatusCode.OK.getCode()).msg(StatusCode.OK.getMessage());
    }

    public static ResultBody failed() {
        return new ResultBody().code(StatusCode.FAIL.getCode()).msg(StatusCode.FAIL.getMessage());
    }

    public static ResultBody alert() {
        return new ResultBody().code(StatusCode.ALERT.getCode()).msg(StatusCode.ALERT.getMessage());
    }

    public ResultBody code(int code) {
        this.code = code;
        return this;
    }

    public ResultBody msg(String message) {
        this.message = message;
        //i18n(ErrorCode.getResultEnum(this.code).getMessage(), message);
        return this;
    }

    public ResultBody data(T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return "ResultBody{" +
                "code=" + code +
                ", msg='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
